-
Notifications
You must be signed in to change notification settings - Fork 3.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Pull the correct collection plugin for the product #15658
base: devel
Are you sure you want to change the base?
Conversation
126d887
to
4bf0ba8
Compare
awx_entry_points = {ep.name: ep for ep in entry_points(group='awx_plugins.inventory')} | ||
supported_entry_points = {ep.name: ep for ep in entry_points(group='awx_plugins.inventory.supported')} | ||
entry_points = awx_entry_points if detect_server_product_name() == 'AWX' else {**awx_entry_points, **supported_entry_points} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Perhaps, it's better to skip the lookup altogether when not needed?
awx_entry_points = {ep.name: ep for ep in entry_points(group='awx_plugins.inventory')} | |
supported_entry_points = {ep.name: ep for ep in entry_points(group='awx_plugins.inventory.supported')} | |
entry_points = awx_entry_points if detect_server_product_name() == 'AWX' else {**awx_entry_points, **supported_entry_points} | |
awx_entry_points = {ep.name: ep for ep in entry_points(group='awx_plugins.inventory')} | |
supported_entry_points = dict() if detect_server_product_name() == 'AWX' else {ep.name: ep for ep in entry_points(group='awx_plugins.inventory.supported')} | |
entry_points = {**awx_entry_points, **supported_entry_points} |
for entry_point_name, entry_point in entry_points.items(): | ||
cls = entry_point.load() | ||
InventorySourceOptions.injectors[entry_point_name] = cls |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It'd be best if this wasn't happening during the import time but called in some predictable hook point, early in django's lifecycle.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
May I suggest a little refactoring?
awx_entry_points = {ep.name: ep for ep in entry_points(group='awx_plugins.inventory')} | ||
supported_entry_points = {ep.name: ep for ep in entry_points(group='awx_plugins.inventory.supported')} | ||
entry_points = awx_entry_points if detect_server_product_name() == 'AWX' else {**awx_entry_points, **supported_entry_points} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How about
awx_entry_points = {ep.name: ep for ep in entry_points(group='awx_plugins.inventory')} | |
supported_entry_points = {ep.name: ep for ep in entry_points(group='awx_plugins.inventory.supported')} | |
entry_points = awx_entry_points if detect_server_product_name() == 'AWX' else {**awx_entry_points, **supported_entry_points} | |
def _load_all_entry_points_for(entry_point_subsections: list[str], /) -> dict[str, EntryPoint]: | |
return { | |
ep.name: ep | |
for entry_point_category in entry_point_subsections | |
for ep in entry_points(group=f'awx_plugins.{entry_point_category}') | |
} | |
is_awx = detect_server_product_name() == 'AWX' | |
extra_entry_point_groups = () if is_awx else ('inventory.supported', ) | |
entry_points = _load_all_entry_points_for(['inventory', *extra_entry_point_groups]) |
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Although, it probably makes sense to put _load_all_entry_points_for()
into awx_plugins.interfaces
, making it reusable.
@@ -9,6 +9,7 @@ | |||
import copy | |||
import os.path | |||
from urllib.parse import urljoin | |||
from importlib.metadata import entry_points |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
from importlib.metadata import entry_points | |
from importlib.metadata import entry_points, EntryPoint |
SUMMARY
There exist several cases of inventory plugins with the same name but different implementations. Historically, AWX/Controller pivoted on attributes on the inventory source to figure out which ansible inventory to call. Now, instead of a single implementation we've split them into two implementations completely. This PR is to implement the change to pick which one we want and when.
Requires: ansible/awx-plugins#61
ISSUE TYPE
COMPONENT NAME
AWX VERSION
ADDITIONAL INFORMATION